<template>
  <div class="app-container">
    <el-page-header @back="goBack" content="学校信息编辑"></el-page-header>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" style="margin-top: 20px;">
      <el-row>
        <el-col :span="12">
          <el-form-item label="学校中文名称" prop="schoolName">
            <el-input v-model="form.schoolName" placeholder="请输入学校中文名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="学校编码" prop="schoolCode">
            <el-input v-model="form.schoolCode" placeholder="请输入学校编码"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="省份编码" prop="provinceCode">
            <el-input v-model="form.provinceCode" placeholder="请输入省份编码"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="城市编码" prop="cityCode">
            <el-input v-model="form.cityCode" placeholder="请输入城市编码"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="学校层次" prop="schoolLevel">
            <el-input v-model="form.schoolLevel" placeholder="请输入学校层次"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="优势专业类别" prop="majorCategory">
            <el-input v-model="form.majorCategory" placeholder="请输入优势专业类别"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="QS世界排名" prop="qsRank">
            <el-input v-model="form.qsRank" placeholder="请输入QS世界排名"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="校友会排名" prop="alumniRank">
            <el-input v-model="form.alumniRank" placeholder="请输入校友会排名"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="建校日期" prop="establishmentDate">
            <el-date-picker clearable
                            v-model="form.establishmentDate"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="请选择建校日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="主管部门" prop="authority">
            <el-input v-model="form.authority" placeholder="请输入主管部门"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="学校地址" prop="location">
            <el-input v-model="form.location" placeholder="请输入学校地址"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="学校官网URL" prop="officialWebsite">
            <el-input v-model="form.officialWebsite" placeholder="请输入学校官网URL"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="招生电话" prop="admissionPhone">
            <el-input v-model="form.admissionPhone" placeholder="请输入招生电话"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招生邮箱" prop="email">
            <el-input v-model="form.email" placeholder="请输入招生邮箱"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="学校概况" prop="schoolOverview">
            <el-input v-model="form.schoolOverview" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="住宿情况" prop="housingSituation">
            <el-input v-model="form.housingSituation" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="学费与奖学金信息" prop="tuitionAndScholarships">
            <el-input v-model="form.tuitionAndScholarships" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="创建人ID" prop="createUser">
            <el-input v-model="form.createUser" placeholder="请输入创建人ID"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="更新人ID" prop="updateUser">
            <el-input v-model="form.updateUser" placeholder="请输入更新人ID"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="学校简介" prop="schoolOverviewJj">
            <el-input v-model="form.schoolOverviewJj" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="办学性质" prop="natureEducation">
            <el-input v-model="form.natureEducation" placeholder="请输入办学性质"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="学校英文名称" prop="enname">
            <el-input v-model="form.enname" placeholder="请输入学校英文名称"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="招生简章信息" prop="zszp">
            <el-input v-model="form.zszp" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="院校风采图片文字说明" prop="yxftzp">
            <el-input v-model="form.yxftzp" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="院校操场图片文字说明" prop="yxctzp">
            <el-input v-model="form.yxctzp" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="校花照片文字说明" prop="xhzp">
            <el-input v-model="form.xhzp" type="textarea" placeholder="请输入内容" :rows="3"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="招生简章图片URL列表" prop="zszppUrlList">
            <ImageUpload v-model="form.zszppUrlList" :limit="5"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="院校风采图片URL" prop="yxftzpUrl">
            <ImageUpload v-model="form.yxftzpUrl" :limit="1"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="院校操场图片URL" prop="yxctzpUrl">
            <ImageUpload v-model="form.yxctzpUrl" :limit="1"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="学校logo" prop="xhzpUrl">
            <ImageUpload v-model="form.xhzpUrl" :limit="1"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="审核状态" prop="auditState">
            <el-input v-model="form.auditState" placeholder="请输入审核状态"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="注册状态" prop="regState">
            <el-input v-model="form.regState" placeholder="请输入注册状态"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="校园VR链接" prop="vrUrl">
            <ImageUpload v-model="form.vrUrl" :limit="1"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="是否删除" prop="isDel">
            <el-select v-model="form.isDel" placeholder="请选择是否删除" style="width: 100%">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否启用" prop="isEnabled">
            <el-select v-model="form.isEnabled" placeholder="请选择是否启用" style="width: 100%">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="是否985院校" prop="isNine">
            <el-select v-model="form.isNine" placeholder="请选择是否985院校" style="width: 100%">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否211院校" prop="isTwo">
            <el-select v-model="form.isTwo" placeholder="请选择是否211院校" style="width: 100%">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="是否双一流院校" prop="isDouble">
            <el-select v-model="form.isDouble" placeholder="请选择是否双一流院校" style="width: 100%">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="审核时间" prop="auditTime">
            <el-date-picker clearable
                            v-model="form.auditTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="请选择审核时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="goBack">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getInfo, addInfo, updateInfo } from "@/api/cms/school"
import ImageUpload from "@/components/ImageUpload"

export default {
  name: "SchoolEdit",
  components: {
    ImageUpload
  },
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        schoolName: [
          { required: true, message: "学校中文名称不能为空", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    const id = this.$route.params.id
    if (id) {
      this.getInfo(id)
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    getInfo(id) {
      getInfo(id).then(response => {
        this.form = response.data
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id !== undefined) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.goBack()
            })
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.goBack()
            })
          }
        }
      })
    }
  }
}
</script>

<style scoped>
.el-page-header {
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
}
</style>
